package com.chinasoft.ui;

import com.chinasoft.listener.ExitButtonListener;
import com.chinasoft.listener.StartButtonListener;

import javax.swing.*;
import java.awt.*;

public class FirstView {

    // frame 是FirstView类的属性
    JFrame frame = new JFrame();

    // 写无参构造方法
    public FirstView() {

        frame.setLocation(100, 100);
        frame.setSize(815, 655);
        // title 和 icon
        frame.setTitle("骑士夺宝");
        frame.setIconImage(Toolkit.getDefaultToolkit().getImage(TestWindow.class.getResource("/image/person01.png")));

        // 面板对象
        Container pane = frame.getContentPane();
        pane.setLayout(null);

        // 添加 图片
        JLabel lblMainIcon = new JLabel("New label");
        lblMainIcon.setIcon(new ImageIcon(FirstView.class.getResource("/image/2.png")));
        lblMainIcon.setBounds(256, 61, 299, 132);
        pane.add(lblMainIcon);

        // 退出按钮
        JLabel lblExit = new JLabel("New label");
        lblExit.setIcon(new ImageIcon(FirstView.class.getResource("/image/exit-bt01.png")));
        lblExit.setBounds(304, 358, 186, 42);
        lblExit.addMouseListener(new ExitButtonListener());
        pane.add(lblExit);

        // 启动 按钮
        JLabel lblStart = new JLabel("New label");
        lblStart.setIcon(new ImageIcon(FirstView.class.getResource("/image/start02.png")));
        lblStart.setBounds(304, 258, 186, 42);
        // 注册监听器
        lblStart.addMouseListener(new StartButtonListener(frame));
        pane.add(lblStart);

        // 添加背景
        JLabel bg = new JLabel("bg");
        bg.setIcon(new ImageIcon(TestWindow.class.getResource("/image/guanka.png")));
        bg.setBounds(5, 5, 790, 600);
        pane.add(bg);

        frame.setVisible(true);
//        frame.dispose();
    }


    public static void main(String[] args) {
        FirstView fv = new FirstView();
    }
}
